import { Point3d } from "../math/Point3d";

export function dot(pt1, pt2) {
  if (!pt1 instanceof Point3d ||
    !pt2 instanceof Point3d) {
    return;
  }
  return pt1.x * pt2.x
    + pt1.y * pt2.y
    + pt1.z * pt2.z;
}

export function perp(pt1, pt2) {
  if (!pt1 instanceof Point3d ||
    !pt2 instanceof Point3d) {
    return;
  }
  const vec = pt2.minus(pt1);
  let xx = Math.pow(vec.x, 2)
  let yy = Math.pow(vec.y, 2)
  const length = Math.sqrt(xx + yy)
  vec.x *= (1 / length);
  vec.y *= (1 / length);
  return new Point3d(vec.y, -vec.x);
}